package com.my12306.train.controller;

import com.my12306.common.constant.CommonConstants;
import com.my12306.common.model.vo.PageVo;
import com.my12306.common.util.PageUtils;
import com.my12306.common.util.response.ResponseData;
import com.my12306.train.model.entity.RouteScheduleRelationEntity;
import com.my12306.train.service.RouteScheduleRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 里程与车次的api
 *
 * @author wj¦
 * @email
 * @date 2020-07-24 20:58:07
 */
@RestController
@RequestMapping("/rschedul")
public class RouteScheduleRelationController {
    @Autowired
    private RouteScheduleRelationService routeScheduleRelationService;

    /**
     * 列表
     */
    @RequestMapping("/pge/lst")
    public ResponseData list(@RequestBody PageVo pageVo) {
        PageUtils page = routeScheduleRelationService.queryRouteScheduleByPage(pageVo);
        return ResponseData.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public ResponseData info(@PathVariable("id") Long id) {
        RouteScheduleRelationEntity routeScheduleRelation = routeScheduleRelationService.getById(id);
        return ResponseData.ok().put("routeScheduleRelation", routeScheduleRelation);
    }

    /**
     * 保存
     */
    @RequestMapping("/sav")
    public ResponseData save(@RequestBody RouteScheduleRelationEntity routeSchedule) {
        routeScheduleRelationService.saveRouteSchedule(routeSchedule);
        return ResponseData.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/upd")
    public ResponseData update(@RequestBody RouteScheduleRelationEntity routeSchedule) {
        routeScheduleRelationService.updateRouteScheduleById(routeSchedule);

        return ResponseData.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public ResponseData delete(@RequestBody List<Long> ids) {
        routeScheduleRelationService.deleteRouteScheduleByIds(ids, CommonConstants.LogicDelete.no_delet.getValue());
        return ResponseData.ok();
    }

}
